package com.awspaas.user.apps.processforsap.event;

import com.actionsoft.bpms.bo.engine.BO;
import com.actionsoft.bpms.bpmn.engine.core.delegate.ProcessExecutionContext;
import com.actionsoft.bpms.bpmn.engine.listener.InterruptListener;
import com.actionsoft.bpms.bpmn.engine.listener.InterruptListenerInterface;
import com.actionsoft.bpms.bpmn.engine.model.run.delegate.ProcessInstance;
import com.actionsoft.exception.BPMNError;
import com.actionsoft.sdk.local.SDK;
import com.alipay.sofa.common.profile.StringUtil;

import java.util.List;
import java.util.stream.Collectors;

public class FI004CreateValidateForSB extends InterruptListener implements InterruptListenerInterface {
    @Override
    public boolean execute(ProcessExecutionContext ctx) throws Exception {
        ProcessInstance processInstance = ctx.getProcessInstance();

        boolean isty = ctx.isChoiceActionMenu("同意");
        if (isty){
            List<BO> list = SDK.getBOAPI().query("BO_EU_SAP_FIZCLIST").bindId(processInstance.getId()).list();
            for (BO bo1:list){
                String is_bg= bo1.getString("IS_BG");
                String bgdw= bo1.getString("BGDW");
                if ("1".equals(is_bg)){
                    if (StringUtil.isEmpty(bgdw)){
                        //
                        throw new BPMNError("0331", "当是否报关为是时，报关单位必填！");

                    }
                }
            }

        }
        return true;
    }
}
